﻿@model cloudscribe.Core.IdentityServerIntegration.Models.ApiEditViewModel
@using cloudscribe.Core.IdentityServerIntegration
@inject IStringLocalizer<CloudscribeIds4Resources> sr
@{ 
    var claimIndex = 0;
}
@if (Model.CurrentApi != null)
{ 
    <h3>@sr["Claims"] </h3>
    await Html.RenderPartialAsync("AddApiClaimPartial", Model.NewApiClaim);
    @if (Model.CurrentApi.UserClaims.Count > 0)
    {
        <ul class="list-unstyled">
            @foreach (var c in Model.CurrentApi.UserClaims)
            {
            <li class="mt-1 mb-1">
                @c
                <button type="button" class="btn btn-danger btn-sm" data-toggle="modal" data-target="@("#confirmDeleteClaimModal" + claimIndex)">
                    @sr["Delete"]
                </button>
                <form asp-controller="ApiResource" asp-action="DeleteApiClaim"> 
                    <input asp-for="SiteId" type="hidden" />
                    <input name="ApiName" value="@Model.CurrentApi.Name" type="hidden" />
                    <input name="ClaimName" value="@c" type="hidden" />
                    <div class="modal fade" id="@("confirmDeleteClaimModal" + claimIndex)" tabindex="-1" role="dialog" aria-labelledby="@("confirmDeleteClaimHeading" + claimIndex)">
                        <div class="modal-dialog modal-sm" role="document">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <h4 class="modal-title" id="@("confirmDeleteClaimHeading" + claimIndex)">@sr["Confirm Delete"]</h4>
                                    <button type="button" class="close" data-dismiss="modal" aria-label='@sr["Close"]'><span aria-hidden="true">&times;</span></button>
                                </div>
                                <div class="modal-body">
                                    @string.Format(sr["Are you sure you want to delete the claim {0}?"], c)
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-primary" data-dismiss="modal">@sr["Cancel"]</button>
                                    <input type="submit" value='@sr["Delete"]' class="btn btn-danger btn-ok" />
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </li>  
                {
                    claimIndex += 1;
                }
            }
        </ul>      
    }
   
}
